package ctn.contant;

import java.text.ParseException;

import ctn.hibernate.po.CpaFun;
import ctn.hibernate.po.CtnCpaInfo;
import ctn.hibernate.po.CtnCpaVer;
import ctn.service.dto.FunDTO;
import ctn.util.StringUtils;
import ctn.util.jmesa.DateUtils;

public class FunContant {
	public final static String STATUS_WAIT="W";    //未开始
	public final static String STATUS_DEVELOP="D";   //正在开发
	public final static String STATUS_Complete="C";   //已完成 
	
	public static void copyFunToDto(CpaFun fun,FunDTO dto){
		dto.setCompleteDate(fun.getCompleteDate());
		//dto.setCpaID(fun.getId());
		if(fun.getCtnCpaInfo()!=null){
			dto.setCpaID(fun.getCtnCpaInfo().getId());
		}
		dto.setFunName(fun.getFunName());
		dto.setID(fun.getId());
		if(null!=fun.getImplUserId()){
			dto.setImplUserId(fun.getImplUserId().toString());
		}
		if(null!=fun.getCtnCpaVer()){
			dto.setVerId(fun.getCtnCpaVer().getId());
		}
		dto.setFunDesc(fun.getFunDesc());
		dto.setLevel(fun.getLevel());
		dto.setPlanEndDate(fun.getPlanEndDate());
		dto.setStage(new Long(fun.getStage()));
		dto.setStatus(fun.getStatus());
		dto.setStartDate(fun.getStartDate());
		dto.setCreateDate(fun.getCreateDate());
		dto.setCreateName(fun.getCreateName());
		
	}
	
	public static void copyDtoToFun(FunDTO dto,CtnCpaInfo cpaIfo,CtnCpaVer cpaVer,CpaFun fun){
		fun.setCompleteDate(dto.getCompleteDate());
		//fun.setCtnCpaInfo(ctnCpaInfo);
		if(null!=cpaIfo){
			
			fun.setCtnCpaInfo(cpaIfo) ;
		}
		if(null!=cpaVer){
			
			fun.setCtnCpaVer(cpaVer) ;
		}
		fun.setCreateName(dto.getCreateName());
		fun.setFunName(dto.getFunName());
		fun.setId(dto.getID());
		if(dto.getImplUserId()!=null){
			fun.setImplUserId(new Long(dto.getImplUserId()));
		}
		if(dto.getLevel()!=null){			
			fun.setLevel(dto.getLevel());
		}
		if(!StringUtils.isEmptyString(dto.getPlanEndDateStr())){
			try {
				fun.setPlanEndDate(DateUtils.parse("yyyy-MM-dd", dto.getPlanEndDateStr()));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		fun.setFunDesc(dto.getFunDesc());
		fun.setStage(dto.getStage());
		fun.setStatus(dto.getStatus());
		fun.setStartDate(dto.getStartDate());
		fun.setCreateDate(dto.getCreateDate());
		
	}
}
